﻿using System;
using System.Windows.Forms;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using RevitInteractiveUtility.ExternalEventManager;

namespace SampleAndTest.ExternalEventManager.SingleFromDemo
{
	internal class SingleFormRequestB : IRequest
	{
		public SingleFormRequestB(int iRequestId)
		{
			this.m_iRequestId = iRequestId;
		}

		public int RequestId
		{
			get
			{
				return this.m_iRequestId;
			}
		}

		public void DoRequest(object parameters = null)
		{
			UIApplication uiapplication = parameters as UIApplication;
			Reference reference = null;
			try
			{
				reference = uiapplication.ActiveUIDocument.Selection.PickObject((Autodesk.Revit.UI.Selection.ObjectType)1);
			}
			catch
			{
			}
			Transaction transaction = new Transaction(uiapplication.ActiveUIDocument.Document);
			try
			{
				transaction.Start("SingleFormTransaction");
				MessageBox.Show(this.m_iRequestId.ToString() + "事务开启成功！");
				if (reference != null)
				{
					uiapplication.ActiveUIDocument.Document.Delete(reference.ElementId);
				}
				transaction.Commit();
			}
			catch
			{
				MessageBox.Show(this.m_iRequestId.ToString() + "事务开启失败！");
				transaction.RollBack();
			}
		}

		private int m_iRequestId = 1;
	}
}
